package edu.nf.dbutil.result;

import edu.nf.dbutil.ResultSetHandler;
import edu.nf.dbutil.RowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * (自)
 * @author yang
 * @date 2024-05-08
 */
public class BeanHandler<T> implements ResultSetHandler<T> {

    private Class<?> beanClass;

    public BeanHandler(Class<T> beanClass) {
        this.beanClass = beanClass;
    }

    @Override
    public T handle(ResultSet rs) throws SQLException {
        return rs.next() ? (T) RowProcessor.toBean(rs,beanClass) : null;
    }
}
